﻿// JScript 文件
var enumPORT_RC_ROWCOL = 1;	    //先行后列
var enumPORT_RC_COLROW = 2;	    //先列后行

var enumPORT_UD_UPDOWN = 1;	    //从上到下
var enumPORT_UD_DOWNUP = 2;	    //从下到上

var enumPORT_LR_LEFTRIGHT = 1;	//从左到右
var enumPORT_LR_RIGHTLEFT = 2;	//从右到左

var brushWhite = "#ffffff";        //白
var brushBlack = "#000000";		//黑
var brushYellow = "#ffff00";       //黄

var brushZgdl = "#a0dcdc";		    //主干
var brushPxdl = "#e1dcb4";		    //配线
var brushLldl = "#c587cb";		    //联络电缆
var brushZxdl = "#ffff00";		    //专线电缆
var brushWldl = "#8797ff";		    //五类电缆
var brushMultiCd = "#ffff00";      //多成端的刷子

var brushIdle = "#00ff00";		    //空闲
var brushUse = "#0000ff";          //占用
var brushBad = "#ff00ff";		    //坏
var brushYz = "#ffff80";		    //预占
var brushIdleFw = "#808080";		//空闲封网
	
var m_brushFlash = "#ffff00";      //闪烁

/*
var penWhite = "#ffffff";			//白
var penZgdl = "#a0dcdc";			//主干
var penPxdl = "#e1dcb4";			//配线
var penLldl = "#c587cb";			//联络电缆
var penZxdl = "#ffff00";			//专线电缆
var penWldl = "#8797ff";			//五类电缆
var penMultiCd = "#ffff00";        //多成端
*/
//端子面板
function devmod(div)
{
    //function
    this.copyfrommod = copyfrommod;
    this.setModViewRange = setModViewRange;
    this.calculatePortsize = calculatePortsize;
    this.calculateModsize = calculateModsize;
    this.calculatePortOffset = calculatePortOffset;
    this.dispmod = dispmod;
    this.getModHtml = getModHtml;
    this.getPortCdHtml = getPortCdHtml;
    this.getPortHtml = getPortHtml;
    this.getPortleftpos = getPortleftpos;
    this.getPorttoppos = getPorttoppos;
    this.getPortno = getPortno;
    this.getCdColorByCdType = getCdColorByCdType;

    this.EntityNo = 0;          //实体号
    this.devNo = -1;            //设备id
    this.DevBm = "";            //设备编码
    this.devtype = 0;           //设备类型
    this.ColNo = 0;             //列号
    this.BlockNo = 0;           //块号
    this.StartPortNo = 0;       //起始端子号
    this.RowNum = 0;            //端子行数
    this.ColNum = 0;            //端子列数
    this.RowColOrd = 1;         //行列顺序
    this.UpDownOrd = 1;         //上下顺序
    this.LeftRightOrd = 1;      //左右顺序

    this.portcabletype = null;  //成端电缆类型
    this.portcdnum = null;      //成端次数
    this.cdlist = null;         //成端记录
    this.div = div;
    
    this.viewleft = 0;
    this.viewtop = 0;
    this.viewwidth = 0;
    this.viewheight = 0;
    
    this.modleft = 0;
    this.modtop = 0;
    this.modwidth = 0;
    this.modheight = 0;
    
    this.portspace = 1.2;
    this.border = 1.2;
    
    this.portsize = 0;
}

function copyfrommod(devmod)
{
    this.EntityNo       = devmod.EntityNo;
    this.DevBm          = devmod.DevBm;
    this.devNo          = devmod.devNo;
    this.ColNo          = devmod.ColNo;
    this.BlockNo        = devmod.BlockNo;
    this.StartPortNo    = devmod.StartPortNo;
    this.RowNum         = devmod.RowNum;
    this.ColNum         = devmod.ColNum;
    this.RowColOrd      = devmod.RowColOrd;
    this.UpDownOrd      = devmod.UpDownOrd;
    this.LeftRightOrd   = devmod.LeftRightOrd;
}

function setModViewRange(left, top, width, height)
{
    this.viewleft = left;
    this.viewtop = top;
    this.viewwidth = width;
    this.viewheight = height;
    
    this.modleft = this.viewleft;
    this.modtop = this.viewtop;
    this.modwidth = 0;
    this.modheight = 0;
}

function calculatePortsize()
{
    var vrad = ((this.viewwidth - this.border*2)/this.ColNum)/2 - this.portspace;
    var hrad = ((this.viewheight - this.border*2)/this.RowNum)/2 - this.portspace;

    this.portsize = (vrad > hrad) ? hrad : vrad;
}

function calculateModsize()
{
    this.modwidth = (this.portsize + this.portspace) * 2 * this.ColNum + this.border * 2;
    this.modheight = (this.portsize + this.portspace) * 2 * this.RowNum + this.border * 2;;
}

function calculatePortOffset(CdList)
{
    var portnum = this.RowNum*this.ColNum;
    var startportno = this.StartPortNo;
    var endportno = this.StartPortNo + portnum;
    var pos = 0;
    this.portcabletype = new Array(portnum);
    this.portcdnum = new Array(portnum);
    this.cdlist = new Array();
    var tmpitem = null;
    
    for (var i = 0; i < portnum; i++)
    {
        this.portcabletype[i] = enumECABLE_UNKNOWN;
        this.portcdnum[i] = 0;
    }
    if (this.devtype != enumEBOX_MDF)
    {
        for (var i = 0; i < CdList.length; i++)
	    {
		    var pcditem = CdList[i];
		    if ((pcditem.startport >= startportno && pcditem.startport <= endportno) 
		       || (pcditem.endport >= startportno && pcditem.endport <= endportno) 
		       || (startportno >= pcditem.startport && startportno <= pcditem.endport) 
		       || (endportno >= pcditem.startport && endportno <= pcditem.endport))
		    {
		        for (var i = pcditem.startport; i <= pcditem.endport; i++)
		        {
		            pos = i - startportno;
		            if (pos >= 0)
		            {
		                this.portcabletype[pos] = pcditem.cbltype;
		                this.portcdnum[i]++;
		            }
		        }
    		    
		        tmpitem = new cditem();
		        tmpitem.copyfromcd(pcditem);
		        this.cdlist.push(tmpitem);
		    }
	    }
	}
    
}

function dispmod()
{
    var div = document.getElementById(this.div);
    var strHtml = "";
    
    strHtml += this.getModHtml();
    strHtml += this.getPortHtml();
    
    div.innerHTML = strHtml;
}

function getModHtml()
{
    var strHtml = "";
    strHtml += "<v:Rect";
    //增加显示参数
    strHtml += " style='position:absolute"
    strHtml += ";left="+this.modleft  + "px";
    strHtml += ";top="+this.modtop  + "px";
    strHtml += ";width="+this.modwidth  + "px";
    strHtml += ";height="+this.modheight  + "px";
    strHtml += ";z-Index:1;'"
    strHtml += " onclick=\"javascript:getModDzJmpInfo(" + this.devNo + "," + this.devtype + "," + this.StartPortNo + "," + (this.StartPortNo + this.RowNum * this.ColNum - 1) + "," + (this.devtype == 1 ? this.ColNo : -1) + ")\""
    //增加显示参数
    strHtml += "/>"
    /*
    strHtml += "<div ";
    strHtml += " onclick=\"javascript:getModDzJmpInfo(" + this.EntityNo + "," + this.devtype + "," + this.StartPortNo + "," + (this.StartPortNo + this.RowNum * this.ColNum - 1) + "," + (this.devtype == 1 ? this.ColNo : -1) + ")\""
    strHtml += " style='position:absolute";
    strHtml += ";left="+this.modleft  + "px";
    strHtml += ";top="+this.modtop  + "px";
    strHtml += ";width="+this.modwidth  + "px";
    strHtml += ";height="+this.modheight  + "px";
    strHtml += ";z-Index:10;";
    strHtml += "'></div>";
    */
    
    return strHtml;
}

function getModDzJmpInfo(devid, devType, stp, edp, colNo)
{
    getDzJmpInfo(
                {
                    devId : devid, 
                    type  : devType,
                    stp   : stp,
                    edp   : edp
                } , colNo);
}

function getPortCdHtml()
{
    var strHtml = "";
    var left = 0;
    var top = 0;
    var no = 0;
    var color = "";
    
    for (var i = 0; i < this.ColNum; i++)
    {
        for (var j = 0; j < this.RowNum; j++)
        {
            left = this.getPortleftpos(i) - this.portspace;
            top = this.getPorttoppos(j) - this.portspace;
            no = this.getPortno(i, j);
            
            color = this.getCdColorByCdType(this.portcabletype[no-this.StartPortNo]);
            if (this.portcdnum[no-this.StartPortNo] > 1)
            {
                color = this.brushMultiCd;
            }
            
            var strtmp = "";

            strtmp += "<v:Rect";
            //strtmp += "<div";
            //增加显示参数
            strtmp += " fillcolor='"+color+"'";
            strtmp += "strokecolor='"+color+"'";
            strtmp += " style='position:absolute"
            strtmp += ";left=" + left + "px";
            strtmp += ";top=" + top + "px";
            strtmp += ";width=" + (this.portsize + this.portspace)*2  + "px";
            strtmp += ";height=" + (this.portsize + this.portspace)*2  + "px";
            strtmp += ";background-color=" + color;
            strtmp += ";z-Index:2;'"
            strtmp += " onclick=\"javascript:getModDzJmpInfo(" + this.devNo + "," + this.devtype + "," + this.StartPortNo + "," + (this.StartPortNo + this.RowNum * this.ColNum - 1) + "," + (this.devtype == 1 ? this.ColNo : -1) + ")\"";
            //增加显示参数
            strtmp += "/>"
            //strtmp += "'></div>";
            
            strHtml += strtmp;
        }
    }
    
    return strHtml;
}

function getPortHtml()
{
    var strHtml = "";
    var left = 0;
    var top = 0;
    var no = 0;
    
    for (var i = 0; i < this.ColNum; i++)
    {
        for (var j = 0; j < this.RowNum; j++)
        {
            left = this.getPortleftpos(i);
            top = this.getPorttoppos(j);
            no = this.getPortno(i, j);
            
            var strtmp = "";

            strtmp += "<v:oval";
            //strtmp += "<img";
            //增加显示参数
            if (this.devtype == 1)
            {
                strtmp += " id='"+ this.ColNo + "_" + no +"'";
            }
            else
            {
                strtmp += " id='"+ no +"'";
            }    
            strtmp += " title='"+no+"'";
            //strtmp += " alt='"+no+"'";
            //strtmp += " src='images/dz.gif'";
            strtmp += " style='position:absolute"
            strtmp += ";left="+left  + "px";
            strtmp += ";top="+top  + "px";
            strtmp += ";width="+this.portsize*2  + "px";
            strtmp += ";height="+this.portsize*2  + "px";
            strtmp += ";z-Index:3;'"
            strtmp += " onclick=\"javascript:getModDzJmpInfo(" + this.devNo + "," + this.devtype + "," + this.StartPortNo + "," + (this.StartPortNo + this.RowNum * this.ColNum - 1) + "," + (this.devtype == 1 ? this.ColNo : -1) + ")\"";
            //增加显示参数
            strtmp += "/>"
            
            strHtml += strtmp;
        }
    }
    
    return strHtml;
}

function getPortleftpos(index)
{
    var left = 0;

    if (this.RowColOrd == enumPORT_LR_LEFTRIGHT)
    {
        left = this.border + this.viewleft + this.portspace + (this.portsize + this.portspace)*2*index;
    }
    else if(this.RowColOrd == enumPORT_LR_RIGHTLEFT)
    {
        left = this.border + this.viewleft + this.portspace + (this.portsize + this.portspace)*2*(this.ColNum - index - 1);
    }

    return left;
}

function getPorttoppos(index)
{
    var top = 0;

    if (this.UpDownOrd == enumPORT_UD_UPDOWN)
    {
        top = this.border + this.viewtop + this.portspace + (this.portsize + this.portspace)*2*index;
    }
    else if(this.UpDownOrd == enumPORT_UD_DOWNUP)
    {
        top = this.border + this.viewtop + this.portspace + (this.portsize + this.portspace)*2*(this.RowNum - index - 1);
    }
    
    return top;
}

function getPortno(left, top)
{
    var portno = 0;

    if (this.RowColOrd == enumPORT_RC_ROWCOL)
    {
_BREAK1:
        for (var i = 0; i < this.RowNum; i++)
        {
            for (var j = 0; j < this.ColNum; j++)
            {
                if (i == top && j == left)
                    break _BREAK1;
                portno++;
            }
        }
    }
    else if(this.RowColOrd == enumPORT_RC_COLROW)
    {
_BREAK2:
        for (var i = 0; i < this.ColNum; i++)
        {
            for (var j = 0; j < this.RowNum; j++)
            {
                if (i == left && j == top)
                    break _BREAK2;
                portno++;
            }
        }
    }
    
    return (portno + this.StartPortNo);
}

function getCdColorByCdType(cdtype)
{
    var color = "#ffffff";
    
    switch (cdtype)
    {
    case enumECABLE_ZG:
        color = brushZgdl;
        break;
    case enumECABLE_PX:
        color = brushPxdl;
        break;
    case enumECABLE_ZJ:
        color = brushLldl;
        break;
    case enumECABLE_LL:
        color = brushLldl;
        break;
    case enumECABLE_WL:
        color = brushWldl;
        break;
    case enumECABLE_YY:
        color = brushWldl;
        break;
    case enumECABLE_CWL:
        color = brushWldl;
        break;
    case enumECABLE_SL:
        color = brushWldl;
        break;
    //增加电缆类型
    default:
        break;
    }
    
    return color;
}
